import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { AiTrainingDatasetVersionsApi } from '#/api/ai/dataset/trainingDatasetVersions';
import type { DescriptionItemSchema } from '#/components/description';

import { h } from 'vue';

import { Typography } from 'ant-design-vue';

const { Paragraph } = Typography;
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'datasetId',
      label: '数据集id',
      rules: 'required',
      component: 'InputNumber',
      componentProps: {
        min: 0,
        placeholder: '请输入数据集id',
      },
    },
    {
      fieldName: 'versionNum',
      label: '版本号',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入版本号',
      },
    },
    {
      fieldName: 'source',
      label: '数据来源，如：manual/auto/imported',
      component: 'Input',
      componentProps: {
        placeholder: '请输入数据来源，如：manual/auto/imported',
      },
    },
    {
      fieldName: 'totalSamples',
      label: '数据总数',
      component: 'InputNumber',
      componentProps: {
        min: 0,
        placeholder: '请输入数据总数',
      },
    },
    {
      fieldName: 'description',
      label: '数据集介绍',
      component: 'RichTextarea',
    },
    {
      fieldName: 'taskType',
      label:
        '阶段类型：sft-监督微调 pretrain-预训练 dpo-直接偏好优化 kto-Kullback-Leibler偏好调整 ppo-近端策略优化 ',
      component: 'Select',
      componentProps: {
        options: [],
        placeholder:
          '请选择阶段类型：sft-监督微调 pretrain-预训练 dpo-直接偏好优化 kto-Kullback-Leibler偏好调整 ppo-近端策略优化 ',
      },
    },
    {
      fieldName: 'metadata',
      label: '扩展元数据',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入扩展元数据',
      },
    },
    {
      fieldName: 'filePath',
      label: '源文件存放路径',
      component: 'Input',
      componentProps: {
        placeholder: '请输入源文件存放路径',
      },
    },
    {
      fieldName: 'dataFormat',
      label: '数据格式：alpaca, sharegpt, llama2, custom',
      component: 'Input',
      componentProps: {
        placeholder: '请输入数据格式：alpaca, sharegpt, llama2, custom',
      },
    },
    {
      fieldName: 'changeLog',
      label: '变更说明',
      component: 'Textarea',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入变更说明',
      },
    },
    {
      fieldName: 'status',
      label: '状态：building-构建中,ready-准备完成,deprecated-弃用',
      rules: 'required',
      component: 'Select',
      componentProps: {
        options: [],
        placeholder:
          '请选择状态：building-构建中,ready-准备完成,deprecated-弃用',
      },
    },
  ];
}

/** 详情页字段 */
export function useDetailSchema(): DescriptionItemSchema[] {
  return [
    {
      label: '数据集id',
      field: 'datasetId',
    },
    {
      label: '版本号',
      field: 'versionNum',
    },
    {
      label: '数据来源，如：manual/auto/imported',
      field: 'source',
    },
    {
      label: '数据总数',
      field: 'totalSamples',
    },
    {
      label: '数据集介绍',
      field: 'description',
      render: (val) => h('div', { innerHTML: val }),
    },
    {
      label: '阶段类型',
      field: 'taskTypeName',
    },
    {
      label: '扩展元数据',
      field: 'metadata',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '源文件存放路径',
      field: 'filePath',
    },
    {
      label: '数据格式：alpaca, sharegpt, llama2, custom',
      field: 'dataFormat',
    },
    {
      label: '变更说明',
      field: 'changeLog',
      render: (val) =>
        h('div', {
          innerHTML: val,
          class: 'whitespace-pre-wrap text-sm leading-relaxed',
        }),
    },
    {
      label: '状态：building-构建中,ready-准备完成,deprecated-弃用',
      field: 'statusName',
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'datasetId',
      label: '数据集id',
      component: 'InputNumber',
      componentProps: {
        min: 0,
        placeholder: '请输入数据集id',
      },
    },
    {
      fieldName: 'versionNum',
      label: '版本号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入版本号',
      },
    },
    {
      fieldName: 'source',
      label: '数据来源，如：manual/auto/imported',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入数据来源，如：manual/auto/imported',
      },
    },
    {
      fieldName: 'taskType',
      label:
        '阶段类型：sft-监督微调 pretrain-预训练 dpo-直接偏好优化 kto-Kullback-Leibler偏好调整 ppo-近端策略优化 ',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [],
        placeholder:
          '请选择阶段类型：sft-监督微调 pretrain-预训练 dpo-直接偏好优化 kto-Kullback-Leibler偏好调整 ppo-近端策略优化 ',
      },
    },
    {
      fieldName: 'dataFormat',
      label: '数据格式：alpaca, sharegpt, llama2, custom',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入数据格式：alpaca, sharegpt, llama2, custom',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'DatePicker',
      componentProps: {
        showTime: false,
        format: 'YYYY-MM-DD',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'status',
      label: '状态：building-构建中,ready-准备完成,deprecated-弃用',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [],
        placeholder:
          '请选择状态：building-构建中,ready-准备完成,deprecated-弃用',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<AiTrainingDatasetVersionsApi.TrainingDatasetVersions>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '版本id',
      minWidth: 120,
      visible: false,
    },
    {
      field: 'datasetId',
      title: '数据集id',
      minWidth: 120,
    },
    {
      field: 'versionNum',
      title: '版本号',
      minWidth: 120,
    },
    {
      field: 'source',
      title: '数据来源，如：manual/auto/imported',
      minWidth: 120,
    },
    {
      field: 'totalSamples',
      title: '数据总数',
      minWidth: 120,
    },
    {
      field: 'description',
      title: '数据集介绍',
      minWidth: 120,
    },
    {
      field: 'taskType',
      title:
        '阶段类型：sft-监督微调 pretrain-预训练 dpo-直接偏好优化 kto-Kullback-Leibler偏好调整 ppo-近端策略优化 ',
      minWidth: 120,
    },
    {
      field: 'metadata',
      title: '扩展元数据',
      minWidth: 120,
    },
    {
      field: 'filePath',
      title: '源文件存放路径',
      minWidth: 120,
    },
    {
      field: 'dataFormat',
      title: '数据格式：alpaca, sharegpt, llama2, custom',
      minWidth: 120,
    },
    {
      field: 'changeLog',
      title: '变更说明',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
    },
    {
      field: 'status',
      title: '状态：building-构建中,ready-准备完成,deprecated-弃用',
      minWidth: 120,
    },
    {
      field: 'actions',
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
